<?php
    if (exponent_users_isAdmin() ||  exponent_permissions_check(array("administrate"),$loc))
    {
        //Timeby=hour, date, month
        if($_REQUEST['type']=='send')
        {
            if($_REQUEST['timeby']=="hour")
            {
                $sql="SELECT COUNT( * ) as count , FROM_UNIXTIME( date_insert,'%Y-%m-%d %H:%i:%s' ) as date FROM {$db->prefix}mailsystem_mail GROUP BY  FROM_UNIXTIME( date_insert,'%Y %D %M %h' ) ";
            }
            if($_REQUEST['timeby']=="date")
            {
                $sql="SELECT COUNT( * ) as count , FROM_UNIXTIME( date_insert,'%Y-%m-%d' ) as date FROM {$db->prefix}mailsystem_mail GROUP BY  FROM_UNIXTIME( date_insert,'%Y %D %M' ) ";
            }
            if($_REQUEST['timeby']=="month")
            {
                $sql="SELECT COUNT( * ) as count , FROM_UNIXTIME( date_insert,'%Y-%m-%d' ) as date FROM {$db->prefix}mailsystem_mail GROUP BY  FROM_UNIXTIME( date_insert,'%Y %M' ) ";
            }
            //
            if($_REQUEST['timeby1']=="hour")
            {
                $sql="SELECT COUNT( * ) as count , DATE( FROM_UNIXTIME( date_insert ) ) as date FROM {$db->prefix}mailsystem_mail GROUP BY DATE( FROM_UNIXTIME( date_insert ) ) ";
            }
        }
        else if($_REQUEST['type']=='send')
        {
            
        }
        $mail=$db->selectObjectsBySql($sql);
        $chart=null;
        foreach($mail as $k=>$v)
        {    
            //$v->time=strtotime($v->date).'000';
            $chart[$k][0]=$v->date;
            $chart[$k][1]=$v->count;
        }

        echo json_encode($chart);
    }
?>
